//管理用户数据相关
import {defineStore} from "pinia";

interface UserInfo {
    userId: string,
    userName: string | null,
    userAvatarUrl: string | null,
    account: string,
    userRole: string,//用户角色
    userStatus: string,//用户状态
    userIsVerified: string,//用户是否认证
}

export const useInfoStore = defineStore('user', {

    //存放用户信息
    state: () => {
        return {
            isLogin: false,
            userInfo: {} as UserInfo
        }
    },
    //对数据进行操作
    actions: {
        //设置用户信息
        setUserInfo(userInfo: UserInfo) {
            this.isLogin = true;
            this.userInfo = userInfo
        },
        //设置用户昵称
        setUserName(userName: string) {
            this.userInfo.userName = userName
        },
        //设置用户头像
        setUserAvatarUrl(userAvatarUrl: string) {
            this.userInfo.userAvatarUrl = userAvatarUrl
        },
        //清除用户信息
        clearUserInfo() {
            this.isLogin = false;
            this.userInfo = {} as UserInfo
        }
    },
    //对数据进行计算
    getters: {},
    //持久化
    persist: true,

});